import React, { Component } from "react";

export default class Page4 extends Component {
  constructor() {
    super();
    this.state = {
      score: Math.round(Math.random() * 100), //随机产生一个0到100的整数作为分数
    };
  }

  render() {
    let score = this.state.score;
    let tip = "不及格";
    if (score < 60) {
      tip = "不及格";
    } else if (score < 70) {
      tip = "及格";
    } else if (score < 80) {
      tip = "良好";
    } else {
      tip = "优秀";
    }
    return (
      <div>
        <button
          onClick={() => {
            this.setState({
              score: Math.round(Math.random() * 100),
            });
          }}
        >
          点击刷新分数
        </button>
        分数{this.state.score}{" "}
        {this.state.score < 60
          ? "不及格"
          : this.state.score < 70
          ? "及格"
          : this.state.score < 80
          ? "良好"
          : "优秀"}
        {score < 60
          ? "不及格"
          : score < 70
          ? "及格"
          : score < 80
          ? "良好"
          : "优秀"}
          {tip}
      </div>
    );
  }
}
